package com.itcc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
@RequestMapping("/fileUploading")
public class TestFileUpload {

    @PostMapping
    public String fileUpLoad(@RequestParam("filename") MultipartFile file) throws IOException{

        if(!file.isEmpty()){    //判断选择的文件内容是否为空（内存大小是否为0kb）
            try {
                String filePath = "E:/JavaEE/JavaEeProcedure/resource";
                File dest = new File(filePath + file.getOriginalFilename());    //获取 选择的文件夹的文件名+选择文件的文件名及后缀
                file.transferTo(dest);
                return "success";
            }catch (IOException e){
                return "error";
            }
        }else {
            return "failure";
        }
    }
}
